﻿using FlexFlow.Base.Interface;
using FlexFlow.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FlexFlow.DataProvider.MongoDB
{
    /// <summary>
    /// 表示流程实例提供者的MongoDb实现
    /// </summary>
    public class MongoDbActivityInstanceProvider : MongoDBPhysicalModelProvider<ActivityInstance>,IActivityInstanceProvider
    {
        public override ActivityInstance Create()
        {
            return new ActivityInstance()
            {
                State = ActivityInstanceState.Inactive
            };
        }
        /// <summary>
        /// 更新指定活动实例的状态
        /// </summary>
        /// <param name="actInsId">
        /// 活动实例Id
        /// </param>
        /// <param name="state">
        /// 要更新为的状态
        /// </param>
        /// <returns>
        /// 一个值，表示更新操作是否成功
        /// </returns>
        public bool UpdateState(Guid actInsId, ActivityInstanceState state)
        {
            var upDef = BuildUpdateDef(m => m.State, state);
            return Update(actInsId, upDef);
        }
        /// <summary>
        /// 更新指定活动实例的绑定数据
        /// </summary>
        /// <param name="actInsID">
        /// 活动实例ID
        /// </param>
        /// <param name="data">
        /// 绑定数据
        /// </param>
        /// <returns>
        /// 一个值，表示更新是否成功
        /// </returns>

        public bool UpdateData(Guid actInsID, Dictionary<string, string> data)
        {
            var upDef = BuildUpdateDef(m => m.ExecuteData, data);
            return Update(actInsID, upDef);
        }
    }
}
